#ifndef _BASE_SERVER_H_
#define _BASE_SERVER_H_

#include <macros.h>
#include <sdpipe.h>
#include "sdsvrhandler.h"
#include <sdutility.h>

using namespace SGDP;

class CBaseServer : public SGDP::ISDPipeSink
{
public:
    CBaseServer();
    virtual ~CBaseServer();
    
    ///Interface of ISDPipeSink
    virtual void SDAPI OnRecv(UINT16 wBusinessID, const char *pData, UINT32 dwLen);
    virtual void SDAPI OnReport(UINT16 wBusinessID, INT32 nErrCode);

    void Reset();

    void Init(UINT32 dwSvrID, ISDPipe *poPipe, ISDSvrHandler * poPkgHandle);
    bool Send( const char* pData, UINT32 dwLen);

    void OnConnected();
    void OnDisConnected(INT32 nErrCode);

    UINT32 GetID(void) const { return m_dwSvrID; }

    void SetID(UINT32 val)
    {
        m_dwSvrID = val;
        SGDP::ServerIDitoa(val, m_szSvrID, SVR_ID_LEN);
    }

    ISDSvrHandler* GetPkgHandle() { return m_poPkgHandle; }

private:

    char m_szSvrID[SVR_ID_LEN];
    UINT32 m_dwSvrID;

    ISDPipe * m_poPipe;
    ISDSvrHandler * m_poPkgHandle;
};

#endif
